﻿using DG.Tweening;
using System;
using System.Collections;
using UnityEngine;
using moai_kun_v1;
using moai_kun_v2;


public class Door : MonoBehaviour
{
    private Animator _animator;
    private void Awake()
    {
        _animator = GetComponent<Animator>();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        var player=collision.GetComponent<MainActor>();
        //GameManager.Instance.IncreaseLevel();

        
        if (player && LevelManager.Instance.Finish) 
        {
            AudioManager.Instance.PlaySound(SoundType.Success);
            DoorAnim();
            
        }
    }


    private void DoorAnim()
    {
        Sequence sequence = DOTween.Sequence();
        sequence.AppendCallback(() => { _animator.Play("OpenDoor"); });
        sequence.AppendInterval(2f);
        sequence.AppendCallback(() => { GameMgr.Instance.CurrentPlayer.Hide(); });
        sequence.AppendInterval(1f);
        sequence.AppendCallback(() => { _animator.Play("CloseDoor"); });
        sequence.AppendInterval(2f);
        sequence.AppendCallback(async () => { await GameMgr.Instance.Success(); });
    }

  
}
